
// 栈  先进后出
function Stack() {
  this.arr = [];
  this.add = function (val) {
    return this.arr.push(val)
  };
  this.out = function () {
    return this.arr.pop();
  }
}

let stack = new Stack();
stack.add(1);
console.log(stack.arr);
stack.add(2);
console.log(stack.arr);
stack.add(3);
console.log(stack.arr);

stack.out();
console.log(stack.arr);
stack.out();
console.log(stack.arr);
stack.out();
console.log(stack.arr);

// 队列 先进先出
function Queue() {
  this.arr = [];
  this.add = function (val) {
    return this.arr.push(val)
  };
  this.out = function () {
    return this.arr.shift();
  }
}

let queue = new Queue();
queue.add(1);
console.log(queue.arr);
queue.add(2);
console.log(queue.arr);
queue.add(3);
console.log(queue.arr);

queue.out();
console.log(queue.arr);
queue.out();
console.log(queue.arr);
queue.out();
console.log(queue.arr);